package com.sunwayworld.basemodule.coredata.experimentaltemplate.service.impl;

import com.sunwayworld.basemodule.coredata.experimentaltemplate.bean.LimsExperimentalTemplateTestMethodBean;
import com.sunwayworld.basemodule.coredata.experimentaltemplate.dao.LimsExperimentalTemplateTestMethodDao;
import com.sunwayworld.basemodule.coredata.experimentaltemplate.service.LimsExperimentalTemplateTestMethodService;
import com.sunwayworld.framework.at.annotation.AuditTrailEntry;
import com.sunwayworld.framework.at.annotation.AuditTrailType;
import com.sunwayworld.framework.context.ApplicationContextHelper;
import com.sunwayworld.framework.restful.data.RestJsonWrapperBean;
import com.sunwayworld.framework.spring.annotation.GikamBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
@GikamBean
public class LimsExperimentalTemplateTestMethodServiceImpl implements LimsExperimentalTemplateTestMethodService {

    @Autowired
    private LimsExperimentalTemplateTestMethodDao limsExperimentalTemplateTestMethodDao;

    @Override
    @SuppressWarnings("unchecked")
    public LimsExperimentalTemplateTestMethodDao getDao() {
        return limsExperimentalTemplateTestMethodDao;
    }

    @Override
    @Transactional
    @AuditTrailEntry(AuditTrailType.INSERT)
    public Long insert(RestJsonWrapperBean jsonWrapper) {
        List<LimsExperimentalTemplateTestMethodBean> methodBeans = jsonWrapper.parse(LimsExperimentalTemplateTestMethodBean.class);
        methodBeans.forEach(e -> e.setId(ApplicationContextHelper.getNextIdentity()));
        getDao().insert(methodBeans);
        return methodBeans.get(0).getId();
    }

}
